import { ArgumentsHost, Catch, ExceptionFilter } from '@nestjs/common';
import { Response } from 'express';
import { Response as LuckyResponse } from '../utils';
import { UnknowException } from '../exceptions/unKnowException';

@Catch(UnknowException)
export class UnknownExceptionFilter implements ExceptionFilter {
  catch(exception: UnknowException, host: ArgumentsHost) {
    // throw new Error('Method not implemented.');
    const ctx = host.switchToHttp();
    const response = ctx.getResponse<Response>();
    response.json(LuckyResponse.failMsg('未知错误'));
  }
}
